<template>
	<view>
		<view class="uni-header">
			<view class="uni-group">
				<view class="uni-title">切换店铺</view>
			</view>
		</view>
		<view class="uni-container">
			<radio-group @change="changeShop">
				<view v-for="(shop,index) in adminShopList" :key="index" class="margin-bottom-sm">
					<label class="radio">
						<radio :value="shop.id+''" :checked="adminShop.id == shop.id" /><text
							class="margin-left-sm">{{shop.name}}（{{shop.id}}）</text>
					</label>
				</view>
			</radio-group>

			<view class="uni-button-group pointer">
				<button class="uni-button uni-button-full" type="primary" @click="submit">保存</button>
				<button class="uni-button uni-button-full" type="default" @click="close">取消</button>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		mapState,
		mapMutations
	} from 'vuex'
	export default {
		data() {
			return {
				isLoading: false,
				shop: {},
			}
		},
		computed: {
			...mapState('app', ['adminShopList', 'adminShop'])
		},
		methods: {
			...mapMutations({
				resetShop(commit, shop) {
					commit('app/SET_ADMIN_SHOP', shop)
				}
			}),
			changeShop(e) {
				for (let shop of this.adminShopList) {
					if (shop.id == e.detail.value) {
						this.shop = shop;
						console.log("changeShop", e, shop)
					}
				}
			},
			submit() {
				this.resetShop(this.shop);
				this.close();
				//重新进入系统
				setTimeout(() => {
					uni.reLaunch({
						url: "/"
					})
				}, 200)
			},
			close() {
				this.$emit("close");
			}
		}
	}
</script>


<style>
	.uni-forms {
		width: 100%;
	}

	.login-button-width {
		width: 184px;
	}
</style>
